﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TekaMUD.Engine.Commands;
using TekaMUD.Engine.Blocks;
using TekaMUD.Engine.IO;
using TekaMUD.Engine.Framework;
using TekaMUD.Engine.Commands.Parser;

namespace TekaMUD.Engine
{
	/// <summary>
	/// Command queue. Builds commands of the appropriate type and enqueues them on a global queue.
	/// </summary>
	public class CommandQueue
	{
		private static BlockingQueue<Command> queue = new BlockingQueue<Command>();
		private static object SyncRoot = new object();

		public static Command DequeueCommand()
		{
			return queue.Dequeue();
		}

		/// <summary>
		/// Builds a Command and adds it to que command dispatched queue. 
		/// </summary>
		/// <remarks>Also enqueues commands for empty input strings</remarks>
		public static void BuildCommand(BaseChannel channel, Player ra, string s)
		{
			CommandNode cp = CommandLineParser.Parse(s);
			queue.Enqueue(new Command(cp) { Player = ra, Channel = channel });
		}
	}
}